Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance @event decorator #9944

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

feat: enhance @event decorator #9944

wants to merge 20 commits into from

Conversation

ilhan007
Copy link
Member

@ilhan007 ilhan007 commented Sep 26, 2024

Background

The initial goal used to be to better describe our events - which bubble and which can be prevented as part of the API reference docs. While this is the benefit for the end-users, there is another enhancement for component developers, explained below.

Change

The @event decorator is enhanced to provide two new fields describing components' events - cancelable and bubbles, previously configurable via the UI5Element.fireEvent only, allowing more declarative way to configure these event settings:

  • cancelable - if set to true the event can be prevented with preventDefualt() (by default is false)
  • bubbles - if set to false the event will NOT bubble up the DOM tree (by default is true)

Usage

  • Both cancelable and bubbles are false as not configured (false by default):
@event("my-event")
  • Both cancelable and bubbles are true as configured:
@event("my-event", {
	cancelable: true,
	bubbles: true,
})

The fireDecoratorEvent Method

The fireDecoratorEvent method considers the the event decorator.

  • Fires the event with cancelable: false, bubbles: false as they are not configured in the @event
@event("my-event")
this.fireDecoratorEvent("my-event")
  • Fires the event with cancelable: true, bubbles: false, configured in the @event
@event("my-event", {
	cancelable: true,
	bubbles: true,
})
this.fireDecoratorEvent("my-event")

Unlike fireEvent, the fireDecoratorEvent method has only two parameters - the event name and the event detail as the rest of the settings are configurable via the event decorator.

The fireEvent Method

The fireEvent Method does not consider the event decorator and works as before.

  • Fires an event with cancelable: false, bubbles: true as default
this.fireEvent("my-event", { escPressed });
  • Fires an event cancelable: true, bubbles: false, passed as params
this.fireEvent("my-event", { escPressed }, true, false);

API Reference

As mentioned we start showing this information in our website as follows. This comes out of the box, nothing for component developers to take care.

Screenshot 2024-09-30 at 15 52 33

Fixes: #9909

vladitasev
vladitasev previously approved these changes Sep 27, 2024
@ilhan007 ilhan007 changed the title docs: describe non-bubbling events in api ref [draft] feat: enhance @event decorator Sep 27, 2024
@ilhan007 ilhan007 changed the title [draft] feat: enhance @event decorator feat: enhance @event decorator Sep 30, 2024
dobrinyonkov
dobrinyonkov previously approved these changes Oct 2, 2024
@ilhan007 ilhan007 changed the title feat: enhance @event decorator feat: enhance @event decorator Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Select close event handled in popover
3 participants